/**
 * 
 */
package net.sf.tools.uiconfig.model;

import java.io.Serializable;

/**
 * @author sabuj.das
 *
 */
public class Field implements Comparable<Field>, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -9202182675305197181L;
	
	private String uiFieldName;
	private String targetFieldName;
	private Integer displayOrder = 0;
	private boolean visible = true;
	private Configuration configuration;
	
	/**
	 * @param uiFieldName
	 * @param targetFieldName
	 */
	public Field(String uiFieldName, String targetFieldName) {
		this.uiFieldName = uiFieldName;
		this.targetFieldName = targetFieldName;
	}

	/**
	 * @return the uiFieldName
	 */
	public String getUiFieldName() {
		return uiFieldName;
	}

	/**
	 * @param uiFieldName the uiFieldName to set
	 */
	public void setUiFieldName(String uiFieldName) {
		this.uiFieldName = uiFieldName;
	}

	/**
	 * @return the targetFieldName
	 */
	public String getTargetFieldName() {
		return targetFieldName;
	}

	/**
	 * @param targetFieldName the targetFieldName to set
	 */
	public void setTargetFieldName(String targetFieldName) {
		this.targetFieldName = targetFieldName;
	}

	/**
	 * @return the displayOrder
	 */
	public Integer getDisplayOrder() {
		return displayOrder;
	}

	/**
	 * @param displayOrder the displayOrder to set
	 */
	public void setDisplayOrder(Integer displayOrder) {
		this.displayOrder = displayOrder;
	}

	/**
	 * @return the visible
	 */
	public boolean isVisible() {
		return visible;
	}

	/**
	 * @param visible the visible to set
	 */
	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(Field other) {
		if(null == other)
			return 1;
		return this.displayOrder.compareTo(other.displayOrder);
	}

	/**
	 * @return the configuration
	 */
	public Configuration getConfiguration() {
		return configuration;
	}

	/**
	 * @param configuration the configuration to set
	 */
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Field [uiFieldName=" + uiFieldName + ", targetFieldName="
				+ targetFieldName + "]";
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((targetFieldName == null) ? 0 : targetFieldName.hashCode());
		result = prime * result
				+ ((uiFieldName == null) ? 0 : uiFieldName.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Field))
			return false;
		Field other = (Field) obj;
		if (targetFieldName == null) {
			if (other.targetFieldName != null)
				return false;
		} else if (!targetFieldName.equals(other.targetFieldName))
			return false;
		if (uiFieldName == null) {
			if (other.uiFieldName != null)
				return false;
		} else if (!uiFieldName.equals(other.uiFieldName))
			return false;
		return true;
	}
	
	
}
